package com.henu.engineer.service.teacher.pro

import com.henu.engineer.dao.mapper.AuditXmlMapper
import com.henu.engineer.dao.mapper.cultivatingproject.CultivatingGoalXmlMapper
import com.henu.engineer.dao.mapper.cultivatingproject.GraduationRequirementXmlMapper
import com.henu.engineer.dao.mapper.cultivatingproject.IndicatorCourseXmlMapper
import com.henu.engineer.dao.mapper.cultivatingproject.RequirementIndicatorXmlMapper
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Service
import java.time.LocalDate

/**
 * @author noexcept
 * @since 9/25/2021 6:41 PM
 */
@Service
class CultivatingGoalPLService {

    @Autowired
    lateinit var cultivatingGoalXmlMapper: CultivatingGoalXmlMapper

    @Autowired
    lateinit var graduationRequirementXmlMapper: GraduationRequirementXmlMapper

    @Autowired
    lateinit var requirementIndicatorXmlMapper : RequirementIndicatorXmlMapper

    @Autowired
    lateinit var indicatorCourseXmlMapper: IndicatorCourseXmlMapper

    @Autowired
    lateinit var auditXmlMapper: AuditXmlMapper



    fun delCultivatingGoal(id: Int) = cultivatingGoalXmlMapper.deleteCultivatingGoal(id)

    fun updateCultivatingGoal(id: Int, content: String) =
        cultivatingGoalXmlMapper.updateContentById(id, content)

    fun addCultivatingGoal(specialization: String, version: LocalDate, content: String) =
        cultivatingGoalXmlMapper.insertCultivatingGoal(content, specialization, version)


    /**
     * 以下是毕业要求部分
     */


    /**
     * 删除毕业要求的同时，删除所有指标点
     */
    fun delGraduationRequirement(id: Int):Boolean {
        var a=graduationRequirementXmlMapper.deleteSingleById(id)&&
                requirementIndicatorXmlMapper.deleteIndicatorById(id)
        return a;
    }


    fun updateGraduationRequirement(id: Int,name: String, content: String) =
        graduationRequirementXmlMapper.updateNameContentById(id,name, content)

    fun addGraduationRequirement(specialization: String, version: String, name: String, content: String) =
        graduationRequirementXmlMapper.insertSingle(name, content, version, specialization)


    /**
     * 以下是指标点部分
     */


    /**
     * 删除指标点的同时，删除所有课程目标
     */
    fun delRequirementIndicator(id: Int):Boolean {
        var a=requirementIndicatorXmlMapper.deleteIndicatorById(id)&&
                indicatorCourseXmlMapper.deleteByIndicator(id)
        return a;
    }


    fun updateRequirementIndicator(indicatorId: Int,content: String)=
        requirementIndicatorXmlMapper.updateIndicatorContent(indicatorId,content)


    fun  addRequirementIndicator(requirementId:Int,indicatorId:Int,content: String)=
        requirementIndicatorXmlMapper.insertIndicator(requirementId,indicatorId,content)


    /**
     * 以下是课程体系支撑表部分
     */

    fun delIndicatorCourseByIndicatorIdAndCourseSysId(indicatorId: Int,courseSysId:String)=
        indicatorCourseXmlMapper.deleteByIndicatorIdAndCourseSysId(indicatorId,courseSysId)


    fun updateIndicatorCourse(indicatorId: Int, courseSysId: String, intensity: Double)=
        indicatorCourseXmlMapper.updateIntensity(indicatorId,courseSysId,intensity)


    fun addSingleIndicatorCourse(indicatorId: Int, courseSysId: String, intensity: Double)=
        indicatorCourseXmlMapper.insertSingle(indicatorId,courseSysId,intensity)


    /**
     * 通过id查找文件名
     */
    fun  findFilename(id: Int):String=
        auditXmlMapper.selectFilenameByID(id);


    /**
     * 审核
     */

    fun updateAuditTeacherByID(id:Int,status:Int,auditTeacherId:String,auditorsComment:String,auditedDate: LocalDate):Boolean=
        auditXmlMapper.updateAuditTeacherByID(id,status,auditTeacherId,auditTeacherId,auditedDate)
}